package com.eastshop.interceptor;

import org.apache.struts2.ServletActionContext;

import com.eastshop.adminuser.vo.AdminUser;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
/**
 * 权限拦截器
 * @author admin
 *
 */
public class PrivilegeInterceptor extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
		// 判断是否登录
		AdminUser adminUser = (AdminUser) ServletActionContext.getRequest().getSession().getAttribute("admin");
		if(adminUser != null){
			// 已经登录过，放行
			actionInvocation.invoke();
		}{
			// 没有登录，跳转登录页面
			ActionSupport actionSupport = (ActionSupport) actionInvocation.getAction();
			actionSupport.addActionMessage("您还没有登录!没有权限访问!");
			return ActionSupport.LOGIN;
		}
	}

}
